home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 8 / Revista CD Expert nº 08 CD1.iso / Utilitarios / Programacao / Pacific C for DOS / EXAMPLES / READDIR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-08  |  1.2 KB  |  59 lines

  1. /*
  2.  *     This program demonstrates the use of the intdos() function to
  3.  *    make MS-DOS system calls. It would require some modification to
  4.  *    work with any of the large data space memory models.
  5.  */
  6.  
  7. #include    <stdio.h>
  8. #include    <string.h>
  9. #include    <dos.h>
  10.  
  11. struct FMATCH {
  12.     char        filler[21];
  13.     unsigned char    attr;
  14.     unsigned short    time, date;
  15.     unsigned long    size;
  16.     char        name[13];
  17. };
  18.  
  19. static void
  20. putdir(register char * filename)
  21. {
  22.     register unsigned int     fc;
  23.     unsigned long        total;
  24.     union REGS        regs;
  25.     struct FMATCH        file;
  26.  
  27.     regs.h.ah = 0x1a;
  28.     regs.x.dx = (unsigned) &file;
  29.     intdos(®s, ®s);        /* set DTA to file */
  30.     regs.h.ah = 0x4e;
  31.     regs.x.dx = (unsigned) filename;
  32.     regs.x.cx = 0;
  33.     intdos(®s, ®s);        /* get first match */
  34.     total = fc = 0;
  35.     while (!regs.x.cflag) {
  36.         ++fc;            /* increment file count */
  37.         total += file.size;    /* add size to total */
  38.         printf("%s\t", file.name);
  39.         if (strlen(file.name) < 8)
  40.             putchar('\t');
  41.         printf("%8ld\n", file.size);
  42.         regs.h.ah = 0x4f;
  43.         intdos(®s, ®s);    /* get next match */
  44.     }
  45.     printf("%ld bytes in %d files\n", total, fc);
  46. }
  47.  
  48. main()
  49. {
  50.     char    buf[128];
  51.  
  52.     do {
  53.         printf("Wildcard: ");
  54.         gets(buf);
  55.         if (*buf)
  56.             putdir(buf);
  57.     } while (*buf);
  58. }
  59.